<template>
  <transition name="notification-fade">
    <div v-if="visible" class="notification" :class="[`notification-${type}`]">
      <div class="notification-header">
        <h3 class="notification-title">{{ title }}</h3>
        <button class="notification-close" @click="handleClose">&times;</button>
      </div>
      <div class="notification-content">
        <i v-if="icon" :class="icon"></i>
        <div class="notification-message">{{ message }}</div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'FeedbackNotification',
  props: {
    title: {
      type: String,
      default: ''
    },
    message: {
      type: String,
      required: true
    },
    type: {
      type: String,
      default: 'info',
      validator: value => ['success', 'warning', 'info', 'error'].includes(value)
    },
    duration: {
      type: Number,
      default: 4500
    },
    icon: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      visible: false
    }
  },
  mounted() {
    this.visible = true
    if (this.duration > 0) {
      setTimeout(() => {
        this.handleClose()
      }, this.duration)
    }
  },
  methods: {
    handleClose() {
      this.visible = false
      setTimeout(() => {
        this.$destroy()
        this.$el.parentNode.removeChild(this.$el)
      }, 300)
    }
  }
}
</script>

<style scoped>
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 330px;
  padding: 14px 26px 14px 13px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  background: white;
  z-index: 9999;
}

.notification-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.notification-title {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
}

.notification-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
}

.notification-content {
  display: flex;
  align-items: flex-start;
}

.notification-message {
  margin-left: 8px;
  font-size: 14px;
  line-height: 1.5;
}

.notification-success {
  border-left: 4px solid #67c23a;
}

.notification-warning {
  border-left: 4px solid #e6a23c;
}

.notification-info {
  border-left: 4px solid #909399;
}

.notification-error {
  border-left: 4px solid #f56c6c;
}

.notification-fade-enter-active,
.notification-fade-leave-active {
  transition: opacity 0.3s, transform 0.3s;
}

.notification-fade-enter,
.notification-fade-leave-to {
  opacity: 0;
  transform: translateX(100%);
}
</style> 